//
//  KKQuestionTableViewCell.m
//  KKRequestDemo
//
//  Created by Mac mini on 16/1/27.
//  Copyright © 2016年 JuniorCodingPerson. All rights reserved.
//

#import "KKQuestionTableViewCell.h"

@implementation KKQuestionTableViewHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame: frame];
    if (self) {
        
        UIView *lineView = [[UIView alloc] initWithFrame: CGRectMake(15, 0, CGRectGetWidth(frame) - 30, 1)];
        lineView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        lineView.backgroundColor = [UIColor lightGrayColor];
        [self addSubview: lineView];
        
        _kk_headerTitleLabel = [[UILabel alloc] initWithFrame: CGRectMake(15, 5, CGRectGetWidth(frame), 20)];
        _kk_headerTitleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        _kk_headerTitleLabel.backgroundColor = [UIColor clearColor];
        _kk_headerTitleLabel.font = [UIFont systemFontOfSize: 15];
        _kk_headerTitleLabel.textColor = [UIColor blackColor];
        [self addSubview: _kk_headerTitleLabel];
        
        CGFloat pointY = CGRectGetMaxY(_kk_headerTitleLabel.frame);
        
        _kk_headerExplainLabel = [[UILabel alloc] initWithFrame: CGRectMake(15, pointY, CGRectGetWidth(frame), CGRectGetHeight(self.frame) - pointY)];
        _kk_headerExplainLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight;
        _kk_headerExplainLabel.backgroundColor = [UIColor clearColor];
        _kk_headerExplainLabel.font = [UIFont systemFontOfSize: 15];
        _kk_headerExplainLabel.textColor = [UIColor darkGrayColor];
        [self addSubview: _kk_headerExplainLabel];
    }
    return self;
}

- (void)kk_setTitle:(NSString *)title andExplain:(NSString *)explain {
    
    _kk_headerTitleLabel.text = title;
    _kk_headerExplainLabel.text = explain;
}

@end

@implementation KKQuestionTableViewCell

- (void)awakeFromNib {
    // Initialization code
    
    if (_kk_collectionView != nil) {
        [_kk_collectionView registerClass: [KKImageCollectionViewCell class] forCellWithReuseIdentifier:KKImageCollectionViewCellIdentifier];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
    _kk_optionImageView.image = [UIImage imageNamed: selected ? @"button_agree_selected" : @"button_agree_normal"];
}

#pragma mark - Public methods

- (void)kk_setOptionTextFieldHidden:(BOOL)hidden {
    
    _kk_optionTextField.hidden = hidden;
}

#pragma mark - UICollectionView methods

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 10;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    
    return UIEdgeInsetsMake(5, 5, 5, 5);
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier: KKImageCollectionViewCellIdentifier forIndexPath: indexPath];
    
    return cell;
}

@end
